import axios from 'axios'

const Mock = require('mockjs')
const Random = Mock.Random

// 商品列表列表
Mock.mock('/api/getGoodsArray', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      img: Random.image('60x60', '#50B347', '#FFF', 'Mock.js'),
      goodsName: Random.cword(5, 10),
      qrCode: require('@/assets/chain.png'),
      classifyOne: Random.cword(5, 10),
      classifyTwo: Random.cword(5, 10),
      integral: Random.integer(1, 1000),
      stock: Random.integer(1, 1000),
      sort: Random.integer(1, 1000),
      goodsType: Random.pick([1, 2]),
      supplyChain: Random.cword(5, 10),
      creatTime: Random.date('yyyy-MM-dd hh:mm'),
      platform: Random.pick([1]),
      onWay: Random.boolean(),
      recom: Random.boolean(),
      recomIndex: Random.boolean()
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 商品分类列表
Mock.mock('/api/getGoodsClassifyList', () => {
  let list = []
  for (let index = 0; index < 5; index++) {
    let listObject = {
      id: Random.increment(),
      classifyOne: Random.cword(5, 10),
      goodsNum: Random.integer(1, 1000),
      sort: Random.integer(1, 1000),
      recom: Random.boolean(),
      creatTime: Random.date('yyyy-MM-dd hh:mm'),
      openPlatform: Random.pick([1]),
      openStatus: Random.boolean()
    }
    const children = []
    for (let j = 0; j < 4; j++) {
      let childrenObject = {
        id: Random.increment(),
        classifyOneId: listObject.id,
        img: Random.image('60x60', '#50B347', '#FFF', 'Mock.js'),
        classifyTwo: Random.cword(5, 10),
        goodsNum: Random.integer(1, 1000),
        sort: Random.integer(1, 1000),
        recom: Random.boolean(),
        creatTime: Random.date('yyyy-MM-dd hh:mm'),
        openPlatform: Random.pick([1]),
        openStatus: Random.boolean()
      }
      children.push(childrenObject)
    }
    listObject.children = children
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 商品规格列表
Mock.mock('/api/getSpecList', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      name: Random.cword(5, 10),
      isShow: Random.boolean(),
      sort: Random.integer(1, 1000),
      creatTime: Random.date('yyyy-MM-dd hh:mm')
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 商品品牌列表
Mock.mock('/api/getBrandList', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      name: Random.cword(5, 10),
      img: Random.image('60x60', '#50B347', '#FFF', 'Mock.js'),
      isShow: Random.boolean(),
      sort: Random.integer(1, 1000),
      isRecom: Random.boolean(),
      creatTime: Random.date('yyyy-MM-dd hh:mm')
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 商品供应商列表
Mock.mock('/api/getSupplierList', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      name: Random.cword(5, 10),
      logo: Random.image('60x60', '#50B347', '#FFF', 'Mock.js'),
      isShow: Random.boolean(),
      sort: Random.integer(1, 1000),
      goodsNum: Random.integer(1, 1000),
      creatTime: Random.date('yyyy-MM-dd hh:mm')
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 商品标签列表
Mock.mock('/api/getTagList', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      name: Random.cword(5, 10),
      isShow: Random.boolean(),
      sort: Random.integer(1, 1000),
      creatTime: Random.date('yyyy-MM-dd hh:mm')
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

// 关键词列表
Mock.mock('/api/getKeywordsList', () => {
  let list = []
  for (let index = 0; index < 20; index++) {
    let listObject = {
      id: Random.increment(),
      key: Random.cword(5, 10),
      click: Random.integer(1, 1000),
      sort: Random.integer(1, 1000),
      creatTime: Random.date('yyyy-MM-dd hh:mm'),
      openPlatform: Random.pick([1]),
      openStatus: Random.boolean()
    }
    list.push(listObject)
  }
  return {
    list,
    total: Random.integer(1, 20)
  }
})

export function getGoodsArray() {
  return axios.get('/api/getGoodsArray')
}

export function getGoodsClassifyList() {
  return axios.get('/api/getGoodsClassifyList')
}

export function getSpecList() {
  return axios.get('/api/getSpecList')
}

export function getBrandList() {
  return axios.get('/api/getBrandList')
}

export function getSupplierList() {
  return axios.get('/api/getSupplierList')
}

export function getTagList() {
  return axios.get('/api/getTagList')
}

export function getKeywordsList() {
  return axios.get('/api/getKeywordsList')
}
